<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *员工列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
if($_RQ['op']=='edit'){
	$item=pdo_get('jy_yxw_worker',array('id'=>$_SESSION['workerid'],'uniacid'=>$_SESSION['uniacid']));
	if(!$item['id']){
		exi('你不是员工！无法操作！','error');
	}
	$item['password']='';
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'edit'=>array(
					array('type'=>'copy','title'=>'姓名','name'=>'title','help'=>'姓名只能由管理员修改！'),
					array('type'=>'image','title'=>'头像','name'=>'logo','help'=>''),
					array('type'=>'copy','title'=>'登录账号','name'=>'username','help'=>''),
					array('type'=>'password','title'=>'登录密码','name'=>'password','help'=>'不填表示不修改！'),
					array('type'=>'string','title'=>'手机号','name'=>'mobile','help'=>''),
					array('type'=>'radio','title'=>'性别','name'=>'sex','options'=>'sex'),
					array('type'=>'time','title'=>'生日','name'=>'birth','help'=>''),
					array('type'=>'time','title'=>'入职时间','name'=>'add_days','help'=>''),
					array('type'=>'pcd','title'=>'户籍','name'=>'pcd','help'=>''),
					array('type'=>'string','title'=>'详细地址','name'=>'address','help'=>''),
		)
	);
	$return['sex']=$this->sex;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['title']){
		exi('请填写姓名！','error');
	}
	$data=array(
		'title'=>$postdata['title'],
		'logo'=>$postdata['logo'],
		'mobile'=>$postdata['mobile'],
		'add_days'=>$postdata['add_days'],
		'sex'=>intval($postdata['sex']),
		'birth'=>($postdata['birth']),
		'pcd'=>ijson_encode($postdata['pcd']),
		'address'=>$postdata['address'],
		'username'=>$postdata['username'],
	);
	$id=intval($postdata['id']);
	if($postdata['password']){
		$data['password']=base64_encode($postdata['password']);
		$pattern='/^(?=.*[0-9])(?=.*[a-zA-Z]).{8,}$/';
		if(preg_match($pattern,$postdata['password'])){
			
		}else{
			exi('密码长度不得低于8位,且至少包含字母和数字。','error');
		}
		
	}
	if($data['username']){
		$uname=pdo_get('jy_yxw_worker',array('username'=>$data['username'],'uniacid'=>$_SESSION['uniacid']));
	}
	if($uname && $uname['id']!=$id){
		exi('账号不可以重复','error');	
	}
	if($id){
		pdo_update('jy_yxw_worker',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		if(!$postdata['username'] || !$postdata['password']){
			exi('请填写账户和密码！','error');
		}
		exi('只能由管理员或店长添加！','error');
	}
	exi('操作成功！');
}